package com.zhuss.core.user;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.send.ListBySendBo;
import com.zhuss.bean.bo.core.user.CareUserRoleListBo;
import com.zhuss.bean.bo.core.user.DetailUserBo;
import com.zhuss.bean.bo.core.user.SearchUserBo;
import com.zhuss.bean.unit.core.user.UserBean;
import com.zhuss.bean.vo.core.append.DetailUserAppendVo;
import com.zhuss.bean.vo.core.user.CareUserRoleListVo;
import com.zhuss.bean.vo.core.user.DetailUserVo;
import com.zhuss.common.ListVo;
import com.zhuss.common.ReadService;
import com.zhuss.common.SelectVo;
import com.zhuss.core.processor.RoleRead;
import com.zhuss.core.processor.UserAppendRead;
import com.zhuss.core.processor.UserRead;
import com.zhuss.core.processor.UserRoleRead;
import com.zhuss.enums.AppendTypeEnum;
import com.zhuss.exception.WpsException;


/**
 * 用户查询service（基本查询）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("userReadService")
public class UserReadService implements ReadService<Object, Object> {
	
	@Autowired
	@Qualifier("userRead")
	private UserRead userRead;
	
	@Autowired
	@Qualifier("roleRead")
	private RoleRead roleRead;
	
	@Autowired
	@Qualifier("userRoleRead")
	private UserRoleRead userRoleRead;
	
	@Autowired
	@Qualifier("userAppendRead")
	private UserAppendRead userAppendRead;
	
	
	/**
	 * 详情
	 */
	@Override
	public Object detail(Object param) throws WpsException {
		DetailUserBo bo = (DetailUserBo) param;
		Long userId = bo.getUserId();
		Object vo = userRead.detail(userId);
		return vo;
	}
	
	
	/**
	 * userBean
	 * @throws WpsException 
	 */
	public UserBean detailBean(Object param) throws WpsException {
		DetailUserBo bo = (DetailUserBo) param;
		Long userId = bo.getUserId();
		DetailUserVo user = (DetailUserVo) userRead.detail(userId);
		UserBean result = new UserBean();
		BeanUtils.copyProperties(user, result);
		List<DetailUserAppendVo> focusList = userAppendRead.listByType(AppendTypeEnum.关注.key(), null, user.getUserId());
    	List<DetailUserAppendVo> focusByList = userAppendRead.listByType(AppendTypeEnum.关注.key(), user.getUserId(), null);
    	Integer focusNum = focusList.size();
    	Integer focusByNum = focusByList.size();
    	result.setFocusNum(focusNum);
    	result.setFocusByNum(focusByNum);
    	result.setThumbByNum(user.getThumbByNum());
    	result.setFocusList(focusList);
    	result.setFocusByList(focusByList);
		return result;
	}
	
	
	/**
	 * 列表
	 * @throws WpsException 
	 */
	@Override
	public Object list(Object param) throws WpsException {
		SearchUserBo bo = (SearchUserBo) param;
		Object result = userRead.list(bo);
		return result;
	}
	
	/**
	 * 下拉框
	 * 列表
	 * @throws WpsException 
	 */
	public List<SelectVo> listUser(Object param) throws WpsException {
		SearchUserBo bo = (SearchUserBo) param;
		List<SelectVo> result = userRead.listUser(bo);
		return result;
	}
	
	
	/**
	 * 用户的角色列表
	 * @param bo
	 * @return
	 * @throws WpsException 
	 */
	@SuppressWarnings("unchecked")
	public Object careUserRoleList(CareUserRoleListBo bo) throws WpsException {
		
		Long userId = bo.getUserId();
		Integer area = bo.getArea();
		CareUserRoleListVo result = new CareUserRoleListVo();
		result.setRoleIdList((List<Long>)userRoleRead.listRoleId(userId));
		result.setRoleList((List<ListVo>)roleRead.listRole(area));
		return result;
	}
	
	/**
	 * 查询公司列表
	 */
	public Object listByCompany(Object param) throws WpsException {
		ListBySendBo bo = (ListBySendBo) param;
		Long companyId = bo.getCompanyId();
		Object vo = userRead.listSelectByCompany(companyId);
		return vo;
	}
	
	
	
}

